import pymssql

conn = pymssql.connect(server='192.168.1.100', user='sa', password='summit-1', database='Northwind')
cursor = conn.cursor()
cursor.execute("""SELECT TOP 2 CustomerID, CompanyName, Address from Customers """)
for row in cursor:
    print('row = %s' % (row,))
    CustomerID = row[0]
    CompanyName = row[1]
    Address = row[2]
    print('客户ID：{}\n公司：{}\n地址：{}'.format(CustomerID, CompanyName, Address))
conn.close()

with pymssql.connect(server='192.168.1.100', user='sa', password='summit-1', database='Northwind') as conn2:
    with conn2.cursor(as_dict=True) as cursor:
        cursor.execute("""
        CREATE PROCEDURE FindCustomer
            @CompanyName VARCHAR (100)
        AS BEGIN 
            SELECT * FROM Customers WHERE CompanyName = @CompanyName
        END 
        """)
        cursor.callproc('FindCustomer', ('Alfreds Futterkiste',))
        for row in cursor:
            print('CusomerID=%s CompanyName=%s' % (row['CustomerID'], row['CompanyName']))

